package joq.server;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;

public class Response
{
    private Charset charSet;
    private String response;
    private Request req;

    Response(Request req, Charset charSet)
    {
	this.charSet = charSet;
	this.req = req;
	response = "How now brown bureaucrat.\n";
    }

    /**
     * Writes the response to the client socket. The client socket's buffer will
     * be set to the length of the response (to simplify my code, mainly, but
     * it also increases throughput). If this becomes a memory issue, it will
     * need to be replaced.
     * @param client
     * @throws IOException
     */
    public void write(SocketChannel client) throws IOException
    {
	byte[] res = response.getBytes(charSet);
	client.socket().setSendBufferSize(res.length);
	ByteBuffer buffer = ByteBuffer.wrap(res);
	client.write(buffer);
    }
}
